package com.itCar.base.config.enums;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName: HttpStatus
 * @Description: TODO 枚举类型
 * @author: liuzg
 * @Date: 2022/10/28 9:40
 * @Week: 星期五
 * @Version: v1.0
 */
public enum HttpStatus {

    OK(200, "OK"),

    NO_CONTENT(204, "没有内容"),
    BAD_REQUEST(400, "错误的请求"),
    UNAUTHORIZED(401, "未经授权"),
    NOT_FOUND(404, "没有找到"),
    REQUEST_TIMEOUT(408, "请求超时"),

    INTERNAL_SERVER_ERROR(500, "内部服务器错误"),
    NOT_IMPLEMENTED(501, "未实现"),
    BAD_GATEWAY(502, "错误的网关"),
    SERVICE_UNAVAILABLE(503, "服务不可用"),
    ;

    private Integer status;
    private String comment;

    /**
     * 通过状态 获取该状态的说明
     *
     * @param status
     * @return
     */
    public static String getStatusNameByStatus(Integer status) {
        HttpStatus arrObj[] = HttpStatus.values();
        for (HttpStatus obj : arrObj) {
            if (status.intValue() == obj.getStatus().intValue()) {
                return obj.getComment();
            }
        }
        return "";
    }

    /**
     * 获取所有枚举
     *
     * @return
     */
    public static List<Map<String, Object>> getStatusList() {
        List<Map<String, Object>> list = new ArrayList<>();
        HttpStatus arrObj[] = HttpStatus.values();
        for (HttpStatus obj : arrObj) {
            Map<String, Object> map = new HashMap<>();
            map.put("status", obj.getStatus());
            map.put("comment", obj.getComment());
            list.add(map);
        }
        return list;
    }

    HttpStatus(Integer status, String comment) {
        this.comment = comment;
        this.status = status;
    }

    public String getComment() {
        return comment;
    }

    public void setComment(String comment) {
        this.comment = comment;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }
}
